<template>
<div>
  <el-container>
    <el-header height="80%"  width="100%">
      <span style="float: right">欢迎您，{{userName}}&nbsp;&nbsp;&nbsp;<a href="#" @click.prevent="getOut">退出登录</a></span>
      <h2  style="width:100%;text-align: center;float: right" >欢迎使用金讯通快速配送管理系统</h2>
    </el-header>
    <el-container style="margin-top: 10px">
      <el-aside width="200px" height="90%">
        <el-col :span="12" style="width: 100%;height: 100%">
          <el-menu
              default-active="/"
              class="el-menu-vertical-demo"
              text-color="#fff"
              active-text-color="#ffd04b"
              style="background-color: rgb(238, 241, 246)"
              router>
            <el-menu-item index="/operationalData">
              <span  style="color: #2c3e50">运营数据</span>
            </el-menu-item>
            <el-menu-item index="/shopGoods">
              <span  style="color: #2c3e50">商品管理</span>
            </el-menu-item>
            <el-menu-item>
              <span  style="color: #2c3e50" @click="edit">店铺信息管理</span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
  <el-dialog
      title="店铺信息编辑"
      :visible.sync="shopDialogVisible"
      width="30%"
      center>
    <el-form :model="form" :rules="rules" ref="formref" >
      <el-form-item label="店铺名称："  :label-width="formLabelWidth" prop="name">
        <el-input v-model="form.name" autocomplete="off" style="width: 80%;float:left;"></el-input>
      </el-form-item>
      <el-form-item label="店铺法人：" :label-width="formLabelWidth" prop="legalPerson">
        <el-input v-model="form.legalPerson" autocomplete="off" style="width: 80%;float:left;"></el-input>
      </el-form-item>
      <el-form-item label="成立时间："  :label-width="formLabelWidth" prop="creatTime">
        <el-date-picker
            v-model="form.creatTime"
            type="date"
            placeholder="选择时间"
            align="right"
            style="width: 80%;float:left;"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="所在位置："  :label-width="formLabelWidth" prop="address">
        <el-input v-model="form.address" autocomplete="off" style="width: 80%;float:left;"></el-input>
      </el-form-item>
      <el-form-item label="店铺类型："  :label-width="formLabelWidth" prop="shopTypeId">
        <el-select v-model="form.shopTypeId" clearable placeholder="请选择户型">
          <el-option
              v-for="item in shopType"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              style="width: 80%;float:left;">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注："  :label-width="formLabelWidth" prop="goodsNum">
      <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="form.remark"
          style="width: 80%;float:left;">
      </el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="shopDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="save">确 定</el-button>
  </span>
  </el-dialog>
</div>
</template>

<script>
export default {
  name: "shopPage",
  data(){
    return{
      userName:'',
      userId:'',
      shop:'',
      shopDialogVisible:false,
      formLabelWidth:'100px',
      shopType:[],
      form:{
        id:'',
        name:'',
        legalPerson:'',
        creatTime: '',
        address:'',
        remark:'',
        shopTypeId:'',
      },
      rules: {
        name: [
          { required: true, message: '请输入店铺名称', trigger: 'blur' },
        ],
        legalPerson: [
          { required: true, message: '请输入店铺法人', trigger: 'blur' },
        ],
        creatTime: [
          { required: true, message: '请输入成立时间', trigger: 'blur' },
        ],
        address: [
          { required: true, message: '请输入家庭住址', trigger: 'blur' },
        ],
        shopTypeId: [
          { required: true, message: '请选择店铺类型', trigger: 'blur' },
        ],
      },
    }
  },
  methods:{
    async getUser(){
      let user=JSON.parse(sessionStorage.getItem('user'))
      this.userName=user.name
      this.userId=user.id
    },
    getOut(){
      sessionStorage.clear()
      this.$router.push('/login')
    },
    async edit(){
      let resp=await this.$axios.get('/manager/queryShop?managerId='+this.userId)
      let shop=resp.data.data
      this.form.id=shop.id
      this.form.name=shop.name
      this.form.legalPerson=shop.legalPerson
      this.form.creatTime= shop.creatTime
      this.form.address=shop.address
      this.form.remark=shop.remark
      this.form.shopTypeId=shop.shopType.id
      this.shopDialogVisible=true
    },
    save(){
      this.$refs.formref.validate( async (valid) => {
        if (valid) {
          let resp = await this.$axios.get('/shop/update',{
            params:this.form
          })
          if(resp.data.code===200){
            this.shopDialogVisible=false
          }else{
            alert('编辑失败')
            this.shopDialogVisible=false
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    async queryType(){
      let resp=await this.$axios.get('/shop/queryShopType')
      this.shopType=resp.data.data
    },
    async queryShop(){
      let resp=await this.$axios.get('/manager/queryShop?managerId='+this.userId)
      let shop=resp.data.data
      sessionStorage.setItem('shopId',shop.id+','+shop.name)
    }
  },
  created() {
    this.getUser()
    this.queryType()
    this.queryShop()
  }
}
</script>

<style scoped>

</style>